﻿using System;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.pp.para;
using SharpSqlAnalyzer.pp.processor.type.comm;
using SharpSqlAnalyzer.pp.stmtformatter;
using SharpSqlAnalyzer.pp.utils;
using SharpSqlAnalyzer.stmt.mssql;

namespace SharpSqlAnalyzer.pp.processor.type.ifstmt
{
	// Token: 0x02000241 RID: 577
	public class IfStmtBEProcessor : AbstractProcessor
	{
		// Token: 0x060012F9 RID: 4857 RVA: 0x0031BDE4 File Offset: 0x00319FE4
		public override void process(TParseTreeNode nodeArg)
		{
			TMssqlIfElse tmssqlIfElse = nodeArg as TMssqlIfElse;
			GFmtOpt option = this.Option;
			if (!(tmssqlIfElse.Stmt is TMssqlBlock))
			{
				if (tmssqlIfElse.Stmt != null)
				{
					FormatterFactory.processStatement(this.Option, tmssqlIfElse.Stmt);
				}
				return;
			}
			TMssqlBlock stmt = (TMssqlBlock)tmssqlIfElse.Stmt;
			TSourceToken startToken = tmssqlIfElse.startToken;
			FormatterFactory.processBlockStmt(option, stmt, startToken);
			TCustomSqlStatement elseStmt = tmssqlIfElse.ElseStmt;
			if (elseStmt == null)
			{
				return;
			}
			TSourceToken startToken2 = elseStmt.startToken;
			if (startToken2 == null)
			{
				return;
			}
			TSourceToken tsourceToken = SourceTokenSearcher.backforwardSearch(elseStmt.startToken, 5, "else");
			if (tsourceToken == null)
			{
				return;
			}
			int num = SourceTokenOperator.curColumnNumberVT(startToken);
			SourceTokenOperator.addBefore(option, tsourceToken, SourceTokenOperator.createReturnSourceToken());
			SourceTokenOperator.addBefore(option, tsourceToken, SourceTokenOperator.createWhitespaceSourceToken(num));
			int length = num + option.beStyleIfElseSingleStmtIndentSize;
			SourceTokenOperator.addBefore(option, startToken2, SourceTokenOperator.createReturnSourceToken());
			SourceTokenOperator.addBefore(option, startToken2, SourceTokenOperator.createWhitespaceSourceToken(length));
		}
	}
}
